package com.jiayang.hhotel.presenter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.adapter.NowLiveSearchDialogAdapter;
import com.jiayang.hhotel.bean.AgreeGuestModel;
import com.jiayang.hhotel.listener.OnItemClickListener;
import com.jiayang.hhotel.ui.AgreeGuestActivity;
import com.jiayang.hhotel.ui.ContactPersonActivity;
import com.jiayang.hhotel.ui.ContractActivity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cn.droidlover.xdroidmvp.mvp.XPresent;

/**
 * Created by Administrator on 2017/5/26 0026.
 * 协议客户首页逻辑类
 */

public class AgreeGuestPresenter extends XPresent<AgreeGuestActivity> {
    public void asyncLoad(){
        ArrayList<AgreeGuestModel> lists=new ArrayList<>();
        lists.add(new AgreeGuestModel("名称","11","酒店","111","二丫",12345678910L));
        lists.add(new AgreeGuestModel("名称","11","酒店","111","二丫",12345678910L));
        lists.add(new AgreeGuestModel("名称","11","酒店","111","二丫",12345678910L));
        lists.add(new AgreeGuestModel("名称","11","酒店","111","二丫",12345678910L));
        lists.add(new AgreeGuestModel("名称","11","酒店","111","二丫",12345678910L));
        lists.add(new AgreeGuestModel("名称","11","酒店","111","二丫",12345678910L));
        getV().setAdapter(lists);
    }

    private AlertDialog transferDialog;
    private Intent intent;
    /**
     * 创建编辑按钮对话框
     *
     * @param context 上下文
     */
    public void transferDialog(final Context context){
        final AlertDialog.Builder builder=new AlertDialog.Builder(context);
        View itemView= LayoutInflater.from(context).inflate(R.layout.dialog_now_live_search,null);
        GridView view= (GridView) itemView.findViewById(R.id.gv);
        final List<String> list= Arrays.asList(context.getResources().getStringArray(R.array.transfer_list));
        NowLiveSearchDialogAdapter adapter=new NowLiveSearchDialogAdapter(context, list,-1, new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                transferDialog.dismiss();
                switch (position){
                    case 0://部门
                    case 1://联系人
                        intent = new Intent(context, ContactPersonActivity.class);
                        break;
                    case 2://合同
                        intent=new Intent(context, ContractActivity.class);
                        break;
                }
                context.startActivity(intent);
            }
        });
        view.setAdapter(adapter);
        builder.setView(itemView);
        transferDialog=builder.show();
    }
    private AlertDialog missDialog;
    /**
     * 创建丢失对话框
     *
     * @param context 上下文
     */
    public void createMissDialog(final Context context,final int position){
        final AlertDialog.Builder builder=new AlertDialog.Builder(context);
        View itemView= LayoutInflater.from(context).inflate(R.layout.dialog_miss,null);
        Button yes= (Button) itemView.findViewById(R.id.bt_yes);
        Button no= (Button) itemView.findViewById(R.id.bt_no);
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                missDialog.dismiss();
                getV().getAdapter().setMissList(position);
                //todo 发送请求
            }
        });
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                missDialog.dismiss();
            }
        });
        builder.setView(itemView);
        missDialog=builder.show();
    }
}
